package com.xinzhi.mapper;

import com.xinzhi.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //新增用户
    @Insert("insert into user(id,phonenumber,password,uid) values " + "(0,#{phonenumber},#{encode},1)")
    int insert(@Param("phonenumber") String phonenumber,@Param("encode") String encode);
    //查重
    @Select("select password from user where phonenumber=#{phonenumber}")
    String findUserByUser(@Param("phonenumber") String phonenumber);
    //验证码登录
    @Select("select id,phonenumber,password from user where phonenumber=#{phonenumber} and password=#{password}")
    User logincode(@Param("phonenumber") String phonenumber,@Param("password") String password);
    //修改密码
    @Update("update user set password=#{encode} where phonenumber=#{phonenumber} ")
    int updatepassword(@Param("phonenumber") String phonenumber,@Param("encode") String encode);
    //根据用户名查询用户
    @Select("select * from user where phonenumber=#{phonenumber}")
    User selectByUsername(@Param("phonenumber") String phonenumber);
    //根据用户id查询角色列表
    @Select("select r.name from role r left join user_role ur on r.id = ur.rid left join user u on u.uid = ur.uid where u.uid =#{uid}")
    List<String> selectRolesByUserId(int uid);
    //根据角色列表查询权限列表
    List<String> selectMenuByRoles(@Param("roleCodes")List<String> roleCodes);
}